package com.runa.rccprotocol.analysis;

import com.alibaba.fastjson.JSON;
import com.runa.monitor.comm.dto.newComm.AffiliatePanelVO;
import com.runa.monitor.comm.dto.newComm.HotMeterVO;
import com.runa.monitor.comm.dto.newComm.PanelVO;
import com.runa.monitor.comm.dto.newComm.ValveVO;
import com.runa.persistence.RepositoryServicePersis;
import com.runa.persistence.util.LogUtil;
import com.runa.protocol.util.FaultUtil;
import com.runa.protocol.analysis.ShellBufferAnalysis;
import com.runa.protocol.enums.ByteOrder;
import com.runa.protocol.util.ByteUtil;
import com.runa.rccprotocol.dto.novocon.NococonHeartBeat;
import com.runa.rccprotocol.dto.novocon.NococonRegister;
import com.runa.rccprotocol.dto.runa.RunaConcenAffirmDeny;
import com.runa.rccprotocol.dto.runa.RunaConcenResponseData;
import lombok.extern.slf4j.Slf4j;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author zhuj
 * 潍坊项目丹佛斯设备解析器
 */
@Slf4j
public class NovoconAnalysis extends ShellBufferAnalysis<byte[]> {

    /**
     * 兼容设计，因为此种采集模式无法根据报文分辨测温点和温控器，所以设置该分流器
     */
    private static final Map<String, String> shunt = new ConcurrentHashMap<>();

    public static void setShunt(String novocon, String type) {
        shunt.put(novocon, type);
    }

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

    private String novoconNumber;

    public NovoconAnalysis() {
        super(null, 0);
    }

    private String netEquNo;

    @Override
    public int fill(byte[] data, int length, String n) {
//        this.netEquNo=netEquNo;
        interData = null;
        int begin;
        for (begin = 0; begin < length; begin++) {
            if ((data[begin] & 0xff) == 0x68) {
                break;
            }
        }
        int device = data[begin + 1] & 0xff;
        switch (device) {
            case 0x00:
            case 0x01:
                if (length < begin + 7) return -1;
                if (data[begin + 6] == 0x16) {
                    novoconNumber = ByteUtil.byteToHexString(data, begin + 2, 4);
                    netEquNo = novoconNumber;
                    interData = device == 0 ? new NococonRegister(novoconNumber) : new NococonHeartBeat(novoconNumber);
                    LogUtil.linkDetect(netEquNo, "丹弗斯", data, length, device == 0 ? "注册" : "心跳");
                }
                break;
            case 0x20:
                return cj188MeterData(data, begin, length);
            case 0x25:
                return cj188MeterDataSdt(data, begin, length);
            case 0x44:
                return beaconValveData(data, begin, length);
            case 0x45:
                return temperatureConOfSparkData(data, begin, length);
            case 0x91:
            case 0x90:
                return temperatureController(data, begin, length);
        }
        return 0;
    }

    private int cj188MeterData(byte[] data, int start, int bytes) {
        int begin;
        for (begin = start; begin < bytes; begin++) {
            if ((data[begin] & 0xff) == 0x68 && (data[bytes - 1] & 0xff) == 0x16 && data[begin + 11 + data[begin + 10]] == ByteUtil.sum(data, begin, 11 + data[begin + 10])) {
                break;
            }
        }
        if (begin == bytes) {
            return 0;
        }
        start = begin;
        int index = start;
        RunaConcenResponseData response = new RunaConcenResponseData();
        response.setAddress(novoconNumber);
        HotMeterVO meterData = new HotMeterVO();
        index += 2;
        meterData.setMeterSerial(ByteUtil.byteToHexString(data, index + 3, 4));
        index += 7;
        int ctrl = data[index++] & 0xff;
        int len = data[index++] & 0xff;
        if (bytes < len + start + 13) return -1;
        int ID = ByteUtil.byteToUShort(data, index, ByteOrder.AB);
        index += 2;
        int retain = data[index++];
//        int state = ByteUtil.getByBit(data[58], 6);
//        log.info("state:" + state);
//        if (state == 1) {
//            meterData.setSuccess(false);
//            meterData.setStatus(ByteUtil.bcd2str(data, 57, 2, true));
//            response.addRepData(meterData);
//            log.info("meterData" + JSON.toJSONString(meterData));
//            interData = response;
//            return 0;
//        }
        if (ctrl == 0x81 && (ID == 0x901f || ID == 0x1f90)) {
//            meterData.setSettDateHeatColdVal(ByteUtil.bcdToInt(data, index, 4, true));
            index += 4;
            if ((data[index++] & 0xff) == 8) {
//                meterData.setSettDateHeatColdVal(meterData.getSettDateHeatColdVal() * 1000);
            } else if ((data[index - 1] & 0xff) == 0x11) {
//                meterData.setSettDateHeatColdVal((float) (meterData.getSettDateHeatColdVal() * 277.8));
            }
            meterData.setAccHeat((float) (ByteUtil.bcdToInt(data, index, 4, true) * 0.01));
            index += 4;
            if ((data[index++] & 0xff) == 8) {
                meterData.setAccHeat(meterData.getAccHeat() * 1000);
            } else if ((data[index - 1] & 0xff) == 0x11) {
                meterData.setAccHeat((float) (meterData.getAccHeat() * 277.8));
            }
            meterData.setPower((float) (ByteUtil.bcdToInt(data, index, 4, true) * 0.01));
            index += 5;
            meterData.setFlow((float) (ByteUtil.bcdToInt(data, index, 4, true) * 0.0001));
            index += 4;
            if ((data[index++] & 0xff) == 0x32) {
                meterData.setFlow((float) (meterData.getFlow() * 0.001));
            }
            meterData.setAccFlow((float) (ByteUtil.bcdToInt(data, index, 4, true) * 0.01));
            index += 5;
            meterData.setSupplyTemp((float) (ByteUtil.bcdToInt(data, index, 3, true) * 0.01));
            index += 3;
            meterData.setReturnTemp((float) (ByteUtil.bcdToInt(data, index, 3, true) * 0.01));
            index += 3;
            //不知道干啥的占了3字节
            index += 3;
            try {
                meterData.setMeterDate((sdf.parse(ByteUtil.bcd2str(
                        data, index, 7, true))));
            } catch (ParseException e) {

            }
//            index += 7;
//            int state = ByteUtil.getByBit(data[index+1], 6);
//            if (state==1) meterData.setSuccess(false);
            meterData.setReadDate(new Date());
            response.addRepData(meterData);
            interData = response;
        }
        return bytes - start - len - 13;
    }

    private int cj188MeterDataSdt(byte[] data, int start, int bytes) {
        //校验
        byte check = data[bytes - 2];
        if (check != ByteUtil.sum(data, start, bytes - start - 2)) {
            return 0;
        }
        int index = start;
        RunaConcenResponseData response = new RunaConcenResponseData();
        response.setAddress(novoconNumber);
        HotMeterVO meterData = new HotMeterVO();
        index += 2;
        meterData.setMeterSerial(ByteUtil.byteToHexStringFlip(data, index, 4));
        index += 7;
        int ctrl = data[index++] & 0xff;
        int len = data[index++] & 0xff;
        if (bytes < len + start + 13) return -1;
        int ID = ByteUtil.byteToUShort(data, index, ByteOrder.AB);
        index += 2;
        int retain = data[index++];
        if (ctrl == 0x81 && ID == 0x1f90) {
//            meterData.setSettDateHeatColdVal(ByteUtil.bcdToInt(data, index, 4, false));
            index += 4;
            if ((data[index++] & 0xff) == 8) {
//                meterData.setSettDateHeatColdVal(meterData.getSettDateHeatColdVal() * 1000);
            } else if ((data[index - 1] & 0xff) == 0x11) {
//                meterData.setSettDateHeatColdVal((float) (meterData.getSettDateHeatColdVal() * 277.8));
            }
            meterData.setAccHeat((float) (ByteUtil.bcdToInt(data, index, 4, false) * 0.01));
            index += 4;
            if ((data[index++] & 0xff) == 8) {
                meterData.setAccHeat(meterData.getAccHeat() * 1000);
            } else if ((data[index - 1] & 0xff) == 0x11) {
                meterData.setAccHeat((float) (meterData.getAccHeat() * 277.8));
            }
            meterData.setPower((float) (ByteUtil.bcdToInt(data, index, 4, false) * 0.01));
            index += 5;
            meterData.setFlow((float) (ByteUtil.bcdToInt(data, index, 4, false) * 0.0001));
            index += 4;
            if ((data[index++] & 0xff) == 0x32) {
                meterData.setFlow((float) (meterData.getFlow() * 0.001));
            }
            meterData.setAccFlow((float) (ByteUtil.bcdToInt(data, index, 4, false) * 0.01));
            index += 5;
            meterData.setSupplyTemp((float) (ByteUtil.bcdToInt(data, index, 3, false) * 0.01));
            index += 3;
            meterData.setReturnTemp((float) (ByteUtil.bcdToInt(data, index, 3, false) * 0.01));
            index += 3;
            meterData.setWorkTime(ByteUtil.bcdToInt(data, index, 3, false));
            index += 3;
            try {
                meterData.setMeterDate(sdf.parse(ByteUtil.bcd2str(
                        data, index, 7, false)));
            } catch (ParseException e) {

            }
            index += 7;
            meterData.setStatus(ByteUtil.byteToHexString(data, index, 2));
            meterData.setReadDate(new Date());
            response.addRepData(meterData);
            interData = response;
        }
        return bytes - start - len - 13;
    }

    private int beaconValveData(byte[] data, int start, int bytes) {
        int index = start;
        index += 2;
        String serial = ByteUtil.byteToHexString(data, index, 7);
        index += 7;
        int ctrl = data[index++] & 0xff;
        int len = data[index++] & 0xff;
        if (bytes < start + len + 13) return -1;
        int ID = data[index++] | ((data[index++] & 0xff) << 8);
        int seq = data[index++];
        if (ctrl == 0x81 && ID == 0x1010) {
            RunaConcenResponseData response = new RunaConcenResponseData();
            response.setAddress(novoconNumber);
            ValveVO valveVO = new ValveVO();
//            ValveData valveData = new ValveData();
            valveVO.setValveSerial(serial);
            int runModel = data[index++];
            if ((data[index] & 0xff) != 0xff) {
                valveVO.setActOpen((float) (data[index + 1] + data[index] * 0.01));
            } else {
                valveVO.setActOpen((float) -99);
            }
            index += 2;
            if ((data[index] & 0xff) != 0xff) {
                valveVO.setReturnTemp((float) (data[index + 1] + data[index] * 0.01));
            } else {
                valveVO.setReturnTemp((float) -99);
            }
            index += 2;
            if ((data[index] & 0xff) != 0xff) {
                valveVO.setRemoteSet((float) (data[index + 1] + data[index] * 0.01));
            } else {
                valveVO.setRemoteSet(Float.valueOf(-99));
            }
            index += 2;
//            if ((data[index] & 0xff) != 0xff) {
//                valveData.setSetTemperature((float) (data[index + 1] + data[index] * 0.01));
//            } else {
//                valveData.setSetTemperature(-99);
//            }
            index += 2;
            int valveType = data[index++];
            int P = data[index++] & 0xff;
            int I = data[index++] & 0xff;
            int openUpLimit = data[index++] & 0xff;
            int openDownLimit = data[index++] & 0xff;
            int hystersis = data[index++] & 0xff;
            int ctrlType = data[index++];
            index += 4;
            int fault = data[index] & 0xff;
            valveVO.setFaultCode(FaultUtil.beaconValveFaults(fault));
            valveVO.setStatus(Integer.toHexString(fault));
            valveVO.setReadTime(new Date());
            response.addRepData(valveVO);
            interData = response;
        } else if (ctrl == 0x84) {
            interData = new RunaConcenAffirmDeny(novoconNumber, true);
        } else {
            interData = new RunaConcenAffirmDeny(novoconNumber, false);
        }
        return bytes - start - len - 13;
    }

    private float temperature(byte[] data, int index) {
        String temp = ByteUtil.byteToHexStringFlip(data, index, 3);
        float ret = (float) (Integer.parseInt(temp.substring(1)) * 0.01);
        if (temp.charAt(0) == 'F') {
            return -ret;
        }
        return ret;
    }

    private int temperatureController(byte[] data, int start, int bytes) {
        int index = start;
        index += 2;
        String serial = ByteUtil.byteToHexStringFlip(data, index, 4);
        index += 7;
        int ctrl = data[index++] & 0xff;
        int len = data[index++] & 0xff;
        if (bytes < start + len + 13) return -1;
        int DI = ((data[index++] & 0xff) << 8) | data[index++];
        int ser = data[index++];
        if (ctrl == 0x81 && DI == 0x901f) {
            RunaConcenResponseData response = new RunaConcenResponseData();
            response.setAddress(novoconNumber);
            ValveVO valveVO = new ValveVO();
//            ValveData valveData = new ValveData();
            valveVO.setValveSerial(serial);
            valveVO.setActOpen((float) (data[index++] & 0xff));
            valveVO.setOpenTime(Float.valueOf(ByteUtil.byteToInt(data, index, ByteOrder.DCBA)));
            index += 4;
            int workTime = ByteUtil.byteToInt(data, index, ByteOrder.DCBA);
            index += 4;
            int actions = ByteUtil.byteToInt(data, index, ByteOrder.DCBA);
            index += 4;
            if ((data[index] & 0xff) != 0xff)
                valveVO.setSupplyTemp(temperature(data, index));
            else
                valveVO.setSupplyTemp((float) -99);
            index += 3;
            if ((data[index] & 0xff) != 0xff)
                valveVO.setReturnTemp(temperature(data, index));
            else
                valveVO.setReturnTemp((float) -99);
            index += 3;
            if ((data[index] & 0xff) != 0xff)
                valveVO.setRemoteSet(temperature(data, index));
            else
                valveVO.setRemoteSet((float) -99);
            index += 3;
            float temperature = 0;
            if ((data[index] & 0xff) != 0xff)
                temperature = temperature(data, index);
            index += 3;
            int valveState = data[index++] << 8 | data[index++];
            short panelState = (short) (data[index++] << 8 | data[index++]);
            valveVO.setSoftVersion(String.valueOf(ByteUtil.bcdToInt(data, index, 2, true) * 0.01));
            index += 2;
            valveVO.setHardVersion(String.valueOf((ByteUtil.bcdToInt(data, index, 2, true) * 0.01)));
            index += 2;
            float panelSoftVersion = (float) (ByteUtil.bcdToInt(data, index, 2, true) * 0.01);
            index += 2;
            int panelHardVersion = ByteUtil.bcdToInt(data, index, 2, true);
            index += 2;
            valveVO.setBatteryVol((float) (ByteUtil.bcdToInt(data, index, 2, false) * 0.01));
            index += 2;
            //工作模式
            if (data[index++] == 1 && data[index++] == 4) {
                switch (data[index++]) {
                    case 0:
                        valveVO.setModel(ValveVO.ModelEnum.室温);
                        break;
                    case 1:
                        valveVO.setModel(ValveVO.ModelEnum.开度);
                        break;
                    case 2:
                        valveVO.setModel(ValveVO.ModelEnum.回温);
                        break;
                }
                index += 3;
                if (valveVO.getModel() == ValveVO.ModelEnum.开度) {
                    valveVO.setRemoteSet((float) data[index]);
                }
            }
            if (data[index++] == 2 && data[index++] == 1) {
                valveVO.setOpenLock(data[index++] == 1);
            }
            if (data[index++] == 3 && data[index++] == 2) {
                valveVO.setOpenDL((float) (data[index++] & 0xff));
                valveVO.setOpenUL((float) (data[index++] & 0xff));
            }
            if (data[index++] == 4 && data[index++] == 2) {
                int using = data[index++] & 1;
                int interval = data[index++] & 0xff;
            }
            if (data[index++] == 5 && data[index++] == 7) {
                String time = ByteUtil.bcd2str(data, index, 7, true);
                index += 7;
                try {
                    valveVO.setValveDate(sdf.parse(time));
                } catch (ParseException e) {
                    //TODO
                }
            }
            if (data[index++] == 6 && data[index++] == 1) {
                int caliber = data[index++];
            }
            if (data[index++] == 7 && data[index++] == 4) {
                int startMonth = ByteUtil.bcdToInt(data, index++, 1, true);
                int startDay = ByteUtil.bcdToInt(data, index++, 1, true);
                int endMonth = ByteUtil.bcdToInt(data, index++, 1, true);
                int endDay = ByteUtil.bcdToInt(data, index++, 1, true);
            }
            if (data[index++] == 8 && data[index++] == 3) {
                valveVO.setTempLock((data[index++] & 1) == 1);
                float lt = Float.parseFloat("."+data[index++]) + data[index++];
                if (valveVO.getModel() == ValveVO.ModelEnum.回温) valveVO.setRemoteSet(lt);
            }
            if (data[index++] == 9 && data[index++] == 4) {
                valveVO.setTempDL((float) (ByteUtil.bcdToInt(data, index, 2, false) * 0.01));
                index += 2;
                valveVO.setTempUL((float) (ByteUtil.bcdToInt(data, index, 2, false) * 0.01));
                index += 2;
            }
            if (data[index++] == 10 && data[index++] == 2) {
                float temperatureCompensation = (float) (ByteUtil.bcdToInt(data, index, 2, false) * 0.01);
                index += 2;
            }
            if (data[index++] == 11 && data[index++] == 1) {
                int minute = data[index++] & 0xff;
            }
            if (data[index++] == 12 && data[index++] == 1) {
                int minute = data[index++] & 0xff;
            }
            if (data[index++] == 13 && data[index++] == 2) {
                float tempDiff = (float) (ByteUtil.bcdToInt(data, index, 2, false) * 0.01);
                index += 2;
            }
            if (data[index++] == 14 && data[index++] == 4) {
                index += 4;
            }
            if (data[index++] == 15 && data[index++] == 4) {
                int accH = ByteUtil.byteToInt(data, index, ByteOrder.DCBA);
                index += 4;
            }
            if (data[index++] == 15 && data[index++] == 4) {
                int accH = ByteUtil.byteToInt(data, index, ByteOrder.DCBA);
                //                    valveData.setAccHeat(accH * 0.01);
            }
            valveVO.setStatus(Integer.toHexString(valveState));
            valveVO.setFaultCode(FaultUtil.novoconValveFaults(valveState));
            valveVO.setReadTime(new Date());
            String type = shunt.get(novoconNumber + serial);
            if ("V".equals(type)) {
                AffiliatePanelVO panel = new AffiliatePanelVO(0, panelHardVersion, temperature, panelState);
                panel.setReadTime(valveVO.getReadTime());
                panel.setSerial(valveVO.getValveSerial());
                valveVO.getPanelVOList().add(panel);
                response.addRepData(valveVO);
            } else if ("T".equals(type)) {
                PanelVO panel = new PanelVO(0, 0, (float) temperature, panelState);
                panel.setSerial(valveVO.getValveSerial());
                response.addRepData(panel);
            }
            interData = response;
        } else if (ctrl == 0x84) {
            interData = new RunaConcenAffirmDeny(novoconNumber, true);
        } else {
            interData = new RunaConcenAffirmDeny(novoconNumber, false);
        }
        return bytes - start - len - 13;
    }


    //6845 41272422631235 811C 0035 0001051905090018015044010700010020070201000000000501 EA16
    private int temperatureConOfSparkData(byte[] data, int start, int bytes) {
        int index = start;
        index += 2;
//        String serial = ByteUtil.byteToHexStringFlip(data, index, 7);
        String serial = ByteUtil.bcd2str(data, index, 7, true);
        index += 7;
        int ctrl = data[index++] & 0xff;
        int len = data[index++] & 0xff;
        if (bytes < start + len + 13) return -1;
        int DI = ((data[index++] & 0xff) << 8) | data[index++];
        int ser = data[index++];
        if (ctrl == 0x81 && DI == 0x0035) {
            RunaConcenResponseData response = new RunaConcenResponseData();
            response.setAddress(novoconNumber);


            PanelVO panelData = new PanelVO();
            panelData.setSerial(serial);
//            panelData.setTc(true);
//            int indoorTemperatureAlarmStatus = data[index] & 0xff;
            index++;
            Short actualRoomTemperature = ByteUtil.byteToShort(data, index, ByteOrder.AB);
            index += 2;
//            double roomTemperature = ByteUtil.bcdToInt(data, index, 2, false) * 0.01;
            index += 2;
//            double indoorTemperatureLimitValue = ByteUtil.bcdToInt(data, index, 2, false) * 0.01;
            index += 2;
//            int heatingSeasonStatus = data[index] & 0xff;
            index++;
//            int softwareVersion = ByteUtil.bcdToInt(data, index, 4, false);
            index += 4;
            int alarmInformation = data[index] & 0xff;
            index++;//报警信息
            index++;
            int LORAStatus = data[index] & 0xff;
            if (LORAStatus != 0 || "236".equals(actualRoomTemperature)) {
                panelData.setSuccess(false);
            }
            index++;
            String equTime = ByteUtil.bcd2str(data, index, 5, false);
//            index += 5;//LORA离线时间
//            index++;//Spark开窗使能
//            index++;
//            index++;
//            index++;
//            index++;
            panelData.setCounter(0);
            panelData.setTemperature(Float.valueOf(actualRoomTemperature));
            try {
                panelData.setPanelDate(new SimpleDateFormat("yyMMddHHmm").parse(equTime));
            } catch (ParseException e) {

            }
            panelData.setStatus(Integer.toHexString(alarmInformation));
            if ((alarmInformation & 1) == 1) {
                panelData.setFaultCode(Collections.singletonList("低电量报警"));
            }
            response.addRepData(panelData);
            interData = response;
        } else if (ctrl == 0x84) {
            interData = new RunaConcenAffirmDeny(novoconNumber, true);
        } else {
            interData = new RunaConcenAffirmDeny(novoconNumber, false);
        }

        return bytes - start - len - 13;
    }

    public static void main(String[] args) {
//        byte[] bytes = ByteUtil.hexStringToByte("FEFEFE682513419060001111813C1F9003000000005F7EB3FBDFF6DDDDFD7F382FB73BA92020209902034ABA020A3302A2030B2A121B031B02030202022A029AA5011501010101F116FEFEFE682593409060001111813C1F90030000000005632130050505030000172641000035141187002C61430018370057410100472105022320034000000000050021300505000000001816");
//
//        byte[] bytes = ByteUtil.hexStringToByte("FEFEFE682513419060001111813C1F90030000000005009369000500000000170000000035900506002C13190085150061060018331706022320034000000000050093690005000000009E16");

//        byte[] bytes = ByteUtil.hexStringToByte("FEFEFEFE689161130210003D3D8181901F006432DD500267608D0224000000FFFFFFFFFFFF0024006002000000000001010A010100010000030104000000FF020100030200640402001E05072021061912222606010207041001041508030000240904000500400A0200000B01140C01F00D0200050E04000000000F04000000001004000000001104000000001201003216");
//        byte[] bytes = ByteUtil.hexStringToByte("FEFEFEFE689151510210003D3D8181901F0000B0CC6602FE438D0210000000FFFFFFFFFFFF0020003850000000000001010A010100010000030104000000FF020100030200640402001E05072021061912245406010207041001041508030000200904000500400A0200000B01140C01F00D0200050E04000000000F04000000001004000000001104000000001201003316");
//        byte[] bytes = ByteUtil.hexStringToByte("FEFE682000000011902354812E901F120000000005000000000500000000170000155635000000002C003911F010000157442023022709514000503916  ");
//        byte[] bytes = ByteUtil.hexStringToByte("FEFEFEFE689032651010003D3D8182901F000000298E00D127980001000000FFFFFFFFFFFF001400701500000000000A0601010100010021090104000000FF020100030200640402001E05072021090802413806010207041001041508030000200904000500300A030000000B01140C01F00D0200050E04000000000F0400000000100400000000110400000000120100AB16  ");
//        byte[] bytes = ByteUtil.hexStringToByte("FEFE682000000003900836812E901F120342449305034244930500000000170000000035002732122CF01000F010000276212023111608154700308516    ");
        byte[] bytes = ByteUtil.hexStringToByte("6844911709200912348404010000045916");

//        byte[] bytes = ByteUtil.hexStringToByte("FEFE682000000002301803812E901F120000000005000000000500000000170000000035000000002C0020050018760220032022120722453200902316");
//        byte[] bytes = ByteUtil.hexStringToByte("FEFE682000000002301803812E901F120000000005000000000500000000170000000035000000002C00B0070018FF3C3F06999EFEFE682000000002301803812E901F120000000005000000000500000000170000000035000000002C0020050018760220032022120722453200902316");

//        ByteUtil.bcd2str(ByteUtil.hexStringToByte("00EC"), 0, 2, false);
//        Short aShort = ByteUtil.byteToShort(ByteUtil.hexStringToByte("00EC"), 0, ByteOrder.AB);
//
//
        NovoconAnalysis analysis = new NovoconAnalysis();
//        analysis.fill(ByteUtil.hexStringToByte("68 00 00 00 00 58 16"), 7);
        //读热表
//        byte[] bytes = ByteUtil.hexStringToByte("684519285353421235811C0035000000EC00EC00EC0050440107000002000000000000000007015916");
//        byte[] bytes = ByteUtil.hexStringToByte("FE FE FE 68 25 07 55 00 61 00 11 11 81 3C 1F 90 12 00 00 00 00 05 19 41 34 04 05 98 02 00 00 17 85 46 00 00 35 19 91 75 00 2C 63 53 00 08 48 00 31 69 01 04 42 15 21 01 22 20 03 40 00 00 00 00 05 00 41 34 04 05 00 00 00 00 A8 16");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //读阀门
//        bytes = ByteUtil.hexStringToByte("684427136354701234811810100000006405140064002804010A640A05005041020C003616");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //读温控器
//        shunt.put("10040771", "V");
//        bytes = ByteUtil.hexStringToByte("FEFEFEFE689071070410003D3D8181901F0064675B9700675B970000000000FFFFFFFFFFFF002400FFFFFF040400000A0201010100010000030104000000FF020100030200640402001E05072021070719015406010207041115033108030100280904000500400A0200000B01140C01F00D0200050E04000000000F0400000000100400000000110400000000120100EA16");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //设置阀门按百分比控制
//        bytes = ByteUtil.hexStringToByte("68 44 20 68 62 99 74 12 34 C4 03 0F 00 00 BF 16");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //阀门开度
//        bytes = ByteUtil.hexStringToByte("68 44 20 68 62 99 74 12 34 84 05 09 00 00 00 32 AD 16");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //阀门按温度控制
//        bytes = ByteUtil.hexStringToByte("68 44 20 68 62 99 74 12 34 84 04 0F 00 00 01 81 16");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //阀门温度设置
//        bytes = ByteUtil.hexStringToByte("68 44 20 68 62 99 74 12 34 84 05 10 00 00 3C 19 D7 16");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //温控器设置开度
//        bytes = ByteUtil.hexStringToByte("FE FE FE FE 68 90 71 66 01 10 00 3D 3D 84 03");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //阀门开度锁
//        bytes = ByteUtil.hexStringToByte("");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //阀门温度锁
//        bytes = ByteUtil.hexStringToByte("");
//        analysis.fill(bytes, bytes.length);
//        System.out.println(analysis.gain());
//        //阀门上下限
//        bytes = ByteUtil.hexStringToByte("");
        analysis.fill(bytes, bytes.length,"");
        System.out.println(JSON.toJSONString(analysis.gain()));

        System.out.println(Float.parseFloat(".12"));
    }
}
